@extends('admin.layouts.app')

@section('content')

                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">车辆管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="{{url('zadmin/')}}">系统</a></li>
                                    <li><a href="{{url('zadmin/cars')}}">车辆管理</a></li>
                                    <li class="active">添加车辆</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                          <div class="col-lg-12">
                            <div class="card-box">
                            <h2 class="m-t-0 header-title">添加车辆</h2>
                            <hr/>
                             @if(session('rs'))
                              <div class="alert alert-{{session('rs')['status']}}">
                                {{ session('rs')['msg'] }}
                              </div>
                              @endif
                              <div class="row">
                                <div class="col-md-9">
                                  <form class="form-horizontal" role="form" action="{{url('zadmin/cars')}}" enctype="multipart/form-data" method="post" >
                                    <div class="form-group">
                                        <label class="col-md-2 control-label">所属客户</label>
                                        <div class="col-md-10">
                                            <select  class="form-control select2" name="client_id" required="" >
                                              <option value="">请选择</option>
                                              @foreach($clients as $c)
                                              <option value="{{$c->id}}" >{{$c->name}} {{$c->phone}}</option>
                                              @endforeach
                                            </select>
                                        </div>
                                                 
                                    </div>
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">车牌号</label>
                                                  <div class="col-md-10">
                                                      <input type="input" class="form-control" name="car_num" required="" value="{{old('car_num')}}">
                                                  </div>
                                                 
                                              </div>
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">车架号</label>
                                                  <div class="col-md-10">
                                                      <input type="input" class="form-control" name="vin" required="" value="{{old('vin')}}">
                                                  </div>
                                                 
                                              </div>
      <div class="form-group">
          <label class="col-md-2 control-label">品牌</label>
          <div class="col-md-10">
              <select  class="form-control select2 car_brand_id" name="car_brand_id" required="" >
                <option value="">请选择</option>
                @foreach($brands as $brand)
                <option value="{{$brand->id}}" >{{$brand->name}}</option>
                @endforeach
              </select>
          </div>
                                                 
      </div>
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">车系</label>
                                                  <div class="col-md-10">
                                                      <select class="form-control car_serie_id select2" name="car_serie_id" >
                                                        <option value="">选择车系</option>
                                                      </select>
                                                  </div>
                                                 
                                              </div>
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">车型</label>
                                                  <div class="col-md-10">
                  <select class="form-control car_model_id select2" name="car_model_id" >
                                    <option value="">选择车型</option>
                                                      </select>
                                                  </div>
                                                 
                                              </div>
                                              <div class="form-group">
                                                  <label class="col-md-2 control-label">发动机号</label>
                                                  <div class="col-md-10">
                                                      <input type="input" class="form-control" name="vin" required="" value="{{old('vin')}}">
                                                  </div>
                                                 
                                              </div>
        <div class="form-group">
            <label class="col-md-2 control-label">车辆类型</label>
            <div class="col-md-10">
                <select  class="form-control" name="car_type_id">
                  @foreach($types as $type)
                    <option value="{{$type->id}}" >{{$type->name}}</option>
                  @endforeach
                </select>
            </div>
                                                 
        </div>
                                                                                                                 
                                         

                                              <div class="form-group text-center">
                                                  
                                                  <button type="submit" class="btn btn-info waves-effect waves-light">保存</button>
                                              </div>
                                              
                                              
                             {{csrf_field()}}
                                          </form>
                                </div>
                                
                              </div>

                             
                              
                              
                            </div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
@section('js')                        
  <script type="text/javascript">
  $(document).on('change','.car_brand_id',function(){

    var _this    = $(this);
    var brand_id = _this.val();
    var url = "{{url('api/car-series')}}";
       
     $.get(url,{'brand_id':brand_id},function(rs){
            if(rs.status==true) {
                var service = $('.car_serie_id');
                service.empty();
                var opt = '<option value="">请选择车系</option>';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'">'+v.name+'</option>'; 
                });
                 service.append(opt);
                
            }
        })
 });

  $(document).on('change','.car_serie_id',function(){

    var _this    = $(this);
    var serie_id = _this.val();
    var url = "{{url('api/car-models')}}";
       
     $.get(url,{'serie_id':serie_id},function(rs){
            if(rs.status==true) {
                var service = $('.car_model_id');
                service.empty();
                var opt = '';
                $.each(rs.data,function(k,v){
                    opt += '<option value="'+v.id+'">'+v.name+'</option>'; 
                });
                 service.append(opt);                
            }
        })
 });

  </script>                      
 @endsection                       
                        

                  
            
    
       

           



    
       
    
